package sanglh.edu.hsphysics.main;

import sanglh.edu.hsphysics.CONFIG;
import sanglh.edu.hsphysics.CONST;
import sanglh.edu.hsphysics.R;
import sanglh.edu.hsphysics.utils.AppUtils;
import sanglh.edu.hsphysics.utils.DeviceUtils;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

public class FragmentSupport extends FragmentNavigationDrawerItem {

	@Override
	public String getTitle() {
		return getString(R.string.support);
	}

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_support, container,
				false);
		return rootView;
	}

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		inflater.inflate(R.menu.suport, menu);
		menu.findItem(R.id.action_camera)
				.setVisible(
						DeviceUtils.hasCamera(getActivity())
								&& DeviceUtils.hasSDCard());
		super.onCreateOptionsMenu(menu, inflater);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.action_camera) {
			CONFIG.deleteImageFolder(getActivity());
			AppUtils.launchCameraApp(getActivity(),
					CONST.REQUEST_CODE_CAPTURE_IMAGE,
					CONFIG.createImageUri(getActivity()));
		}
		return super.onOptionsItemSelected(item);
	}
}
